home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright (C) 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
- /*
- Program to test whether malloc is mp-safe.
- sproc, and both parent and child do 1000 mallocs.
- */
- #include <malloc.h>
- #include <sys/types.h>
- #include <sys/prctl.h>
- #include <stdio.h>
- #include <assert.h>
-
-
- malloc_init_function()
- {
- extern int malloc_stacktrace_get_depth;
- malloc_stacktrace_get_depth = -1;
- }
-
- void child_entry(void *arg)
- {
- int i;
- for (i = 0; i < 10000; ++i) {
- assert(malloc(3));
- free(malloc(3));
- }
- printf("====== Child: done with 10000 mallocs ------\n");
-
- while (1) {
- /* printf("====== Child: sleeping for 10 seconds ======\n"); */
- sleep(3);
- /* printf("====== Child: calling malloc 5 ======\n"); */
- malloc(5);
- }
- }
-
- main(int argc, char **argv)
- {
- int i;
- malloc(7);
-
- printf("sprocing.\n");
-
- if (sproc(child_entry, PR_SALL, NULL) == -1)
- perror("sproc");
-
- for (i = 0; i < 10000; ++i) {
- assert(malloc(3));
- free(malloc(3));
- }
- printf("------ Parent: done with 10000 mallocs ------\n");
-
- for (i = 0; ; ++i) {
- sleep(1);
- malloc_info(1, -1);
- if (i == 0)
- malloc_reset();
- }
- }
-